FILES := $(shell ls -1 *.cpp)
OBJECTS := $(FILES:.cpp=.o)
DEPENDENCIES := $(FILES:.cpp=.d)
PROGNAME := ../earthprotector
CXXFLAGS = -O2 -g -Wall `sdl-config --cflags` -ISDL/ -ITinyXML/ -ISI/
LDFLAGS = -LSDL/  -LTinyXML/ -LSI/ -lsisdl -lsi -ltinyxml `sdl-config --libs` -lSDL_image -lSDL_ttf -lSDL_gfx -lSDL_mixer


all: $(PROGNAME)
	

%.d:%.cpp
	g++ -MM $(CXXFLAGS) $< | sed 's/\(.*\).o:/\1.o \1.d:/' > $@
	
$(PROGNAME):  $(DEPENDENCIES) $(OBJECTS) libs
	 set -e; g++ -g -o $(PROGNAME) $(OBJECTS) $(LDFLAGS); set +e; 
	

libs: libtinyxml libsisdl  libsi

libsisdl:
	$(MAKE) -C SDL/
	
libtinyxml:
	$(MAKE) -C TinyXML/
	
libsi:
	$(MAKE) -C SI/
	
-include $(DEPENDENCIES)

.PHONY: clean run libsisdl libtinyxml libsi

	
clean:
	rm -f *.o *.d; $(MAKE) -C SI/ clean; $(MAKE) -C SDL/ clean; $(MAKE) -C TinyXML/ clean;
	
